package cn.buk.tms.eotms.response;

import cn.buk.common.util.DateUtil;
import cn.buk.tms.common.dto.flight.BaseChangeOrderDto;
import cn.buk.tms.common.dto.flight.BaseChangeOrderFlightDto;
import cn.buk.tms.eotms.entity.FlightChangeOrder;
import cn.buk.tms.eotms.entity.FlightChangeOrderDetail;
import org.springframework.beans.BeanUtils;

/**
 * 机票改签订单DTO
 * @author yfdai
 */
public class ChangeOrderResponseDto extends BaseChangeOrderDto {


    public static ChangeOrderResponseDto createdBy(FlightChangeOrder o) {
        ChangeOrderResponseDto dto = new ChangeOrderResponseDto();

        BeanUtils.copyProperties(o, dto, "flights");

        dto.setParValue(o.getParvalue());
        dto.setReasonCode(o.getChangeType());

        dto.setOrderStatus(o.getStatus());

        for(FlightChangeOrderDetail detail: o.getFlights()) {
            BaseChangeOrderFlightDto flightDto = new BaseChangeOrderFlightDto();
            BeanUtils.copyProperties(detail.getFlight(), flightDto);
            flightDto.setFltType(detail.getFlightType());

            try {
                flightDto.setDdate(DateUtil.convertToDate(detail.getFlight().getDdate(), "yyyy-MM-dd"));
            } catch (Exception ignored) {

            }

            dto.getFlights().add(flightDto);
        }

        return dto;
    }

    public int getStatus() {
        return this.getOrderStatus();
    }

}
